package com.yao.system.controller;


import com.yao.system.annotation.MyAnnotation;
import com.yao.system.entity.*;
import com.yao.system.service.IResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private IResumeService resumeService;


    /**
     * 普通用户新增简历
     * @param resume
     * @return
     */
    @MyAnnotation
    @PostMapping("/add")
    public Result addResume(@RequestBody Resume resume) {
        return resumeService.addResume(resume);
    }

    /**
     * 普通用户更新简历
     * @param resume
     * @return
     */
    @MyAnnotation
    @PostMapping("/update")
    public Result update(@RequestBody Resume resume) {
        //boolean flag = resumeService.updateById(resume);
        //if (!flag)
        //    return Result.error("修改失败");
        //return Result.ok("修改成功");
        return resumeService.updateResume(resume);
    }

    /**
     * 查询普通用户自身的简历列表
     * @return
     */
    @GetMapping("/list")
    public Result getList() {
        return resumeService.getList();
    }

    /**
     * 查询企业已收到的简历列表
     * @return
     */
    @MyAnnotation
    @GetMapping("/receive/list/{page}/{size}")
    public Result getReceiveResumeList(@PathVariable("page")Integer page,
                                       @PathVariable("size")Integer size) {
        return resumeService.getReceiveResumeList(page,size);
    }

    /**
     * 查询企业今日收到的简历列表
     * @return
     */
    @MyAnnotation
    @GetMapping("/receive/list/today")
    public Result queryReceiveResumeListByDay(){
        return resumeService.queryReceiveResumeListByDay();
    }

    /**
     * 普通用户删除简历
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        boolean flag = resumeService.removeById(id);
        if (!flag)
            return Result.error("删除失败");
        return Result.ok("删除成功");
    }

    /**
     * 查询个人简历
     * @return
     */
    @MyAnnotation
    @GetMapping("/getMyResume")
    public Result getMyResume(){
        return resumeService.getMyResume();
    }

    /**
     * 根据id 查询企业收到的简历详情
     * @return
     */
    @MyAnnotation
    @GetMapping("/getReceiveResume/{id}")
    public Result getReceiveResume(@PathVariable("id")Long id){
        return resumeService.getReceiveResume(id);
    }

    /**
     * 普通用户向岗位投递简历
     * @param jobResume
     * @return
     */
    @MyAnnotation
    @PostMapping("/send")
    public Result sendResume(@RequestBody JobResume jobResume){
        return resumeService.sendResume(jobResume);
    }

    /**
     * 普通用户查询已投递简历的岗位列表
     * @return
     */
    @MyAnnotation
    @GetMapping("/sendJob/list")
    public Result getSendJobList(){
        return resumeService.getSendJobList();
    }



    /**
     * 管理员查询普通用户简历列表
     */
    @MyAnnotation
    @GetMapping("/admin-list/{page}/{size}")
    public Result queryResumeList(@PathVariable("page")Integer page,
                               @PathVariable("size")Integer size){
        return resumeService.queryResumeList(page,size);
    }

    ///**
    // * 管理员修改用户简历
    // */
    //@MyAnnotation
    //@PostMapping("/admin-update")
    //public Result updateResumeAdmin(@RequestBody Resume resume){
    //    return resumeService.updateResumeAdmin(resume);
    //}

    /**
     * 管理员删除用户简历
     */
    @MyAnnotation
    @PostMapping("/admin-delete")
    public Result deleteJobAdmin(@RequestBody Resume resume){
        resumeService.removeById(resume);
        return Result.ok("删除成功");
    }

}
